﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ThouShaltNotBrick.Models;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using Microsoft.Xna.Framework.Content.Pipeline;
using ThouShaltNotBrick.PipelineExtension.Readers;

namespace ThouShaltNotBrick.PipelineExtension
{
    [ContentTypeWriter]
    public sealed class LevelContentTypeWriter : ContentTypeWriter<LevelData>
    {
        #region Overriden Methods
        protected override void Write(ContentWriter pOutput, LevelData pValue)
        {
            // NAME (string)
            // NUMBER OF BRICKS (int)
            //   TYPE_NAME (string)
            //   ROW (int)
            //   COLUMN (int)
            //   INITIAL_BRICK_STATE_INDEX (int)

            pOutput.Write(pValue.Name);

            List<BrickData> brickList = pValue.GetBricks();
            pOutput.Write(brickList.Count);
            foreach (BrickData brick in brickList)
            {
                pOutput.Write(brick.TypeName);
                pOutput.Write(brick.Row);
                pOutput.Write(brick.Column);
                pOutput.Write(brick.InitialBrickStateIndex);
            }
        }

        public override string GetRuntimeReader(TargetPlatform pTargetPlatform)
        {
            return typeof(LevelContentTypeReader).AssemblyQualifiedName;
        }

        public override string GetRuntimeType(TargetPlatform pTargetPlatform)
        {
            return typeof(LevelData).AssemblyQualifiedName;
        }
        #endregion
    }
}